﻿using Butcher.winform.Dto;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
using Traceability.Commont.Domains.AnimalsDomainFiles;
using Traceability.Commont.Domains.BatchManagementFiles;

namespace Butcher.winform.EnterpriseForms
{
    public partial class TareSetes : Form
    {
        public TareSetes()
        {
            InitializeComponent();
            getShop();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            TareSet tare=new TareSet();
            tare.ShoppingDesignationid =Convert.ToInt32(cb_Level.SelectedValue) ;
            tare.Weight =Convert.ToDecimal(MintWeight.Text);
            tare.Rarme = TareSetRemarks.Text;
            tare.MakeASingle = "李斯";
            tare.CrateTime=DateTime.Now;
            tare.UpdateASingle = "李斯";
            tare.UpdateTime = DateTime.Now;
            string url = @"http://localhost:5229/api/Batch/AddTareset";
            HttpClient client = new HttpClient();
            var content = new StringContent(JsonSerializer.Serialize<TareSet>(tare));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            if (info != null)
            {
                MessageBox.Show("新增成功");
            }
            else
            {
                MessageBox.Show("新增失败");
            }
        }

        public void getShop()
        {
            Shopping shopping = new Shopping();
            string url = @"http://localhost:5229/api/Batch/getShop";
            HttpClient client = new HttpClient();
            var content = new StringContent(JsonSerializer.Serialize<Shopping>(shopping));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            var saaa = result;
            var aaa = info["date"].Value<JArray>();
            List<Shopping> enterprises = aaa.ToObject<List<Shopping>>();
            this.cb_Level.DataSource = enterprises;
            this.cb_Level.DisplayMember = "ShoppingDesignationName";
            this.cb_Level.ValueMember = "ShoppingDesignationid";
        }
    }
}
